<?php

/**
 * 
 * @author yuxun
 *
 */
class ApiBaseService extends Service {
	
	/**
	 * 记录接口被调用日志
	 * @param unknown $params
	 * @param unknown $return
	 */
	public static function doLog($params,$return){
		$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$ip = self::getIP();
		$params = json_encode($params);
		$return = json_encode($return);
		
		$array = array(
				'url'      => $url,
				'ip'       => $ip,
				'params'   => $params,
				'return'   => $return,
				'create_time' => time()
		);
		
		$model = new ModApiInvokingLog();
		$model->setAttributes($array, false);
		$model->save();
	}
	
	public static function getIP(){
		if (getenv("HTTP_CLIENT_IP"))
			$ip = getenv("HTTP_CLIENT_IP");
		else if(getenv("HTTP_X_FORWARDED_FOR"))
			$ip = getenv("HTTP_X_FORWARDED_FOR");
		else if(getenv("REMOTE_ADDR"))
			$ip = getenv("REMOTE_ADDR");
		else $ip = "Unknow";
		return $ip;
	}

}